package com.ambimmort.shj.service.device;

import cn.net.greenet.device.td.TdDevice;
import cn.net.greenet.device.td.TddeviceManageService;
import cn.net.greenet.device.ud.UddeviceManageService;
import net.sf.json.JSONArray;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zyt on 2015/7/31.
 */
@Service
public class TdDeviceService {
    @Autowired
    private SessionFactory hibernateSessionFactory;

    /**
     * @param ip
     * @param port
     * @param local_user
     * @param pswd
     * @param freq
     * @param local_path
     * @param desc
     * @param up2ip
     * @param up2port
     * @param up2user
     * @param up2pswd
     */
    public boolean addTddeviceDevice(String ip, String port, String local_user, String pswd, String freq, String local_path, String desc, String up2ip, String up2port, String up2user, String up2pswd) {
        TdDevice bean = new TdDevice();
        bean.setLocal_ip(ip);
        bean.setLocal_port(port);
        bean.setLocal_user(local_user);
        bean.setLocal_pswd(pswd);
        bean.setFreq(freq);
        bean.setLocal_path(local_path);
        bean.setIsRun("0");
        bean.setDesc(desc);
        bean.setUp2_ip(up2ip);
        bean.setUp2_port(up2port);
        bean.setUp2_user(up2user);
        bean.setUp2_pswd(up2pswd);
        boolean flag = false;
        TddeviceManageService tds = new TddeviceManageService();
        flag = tds.insert(bean);
        return flag;
    }

    /**
     *
     * @param ip
     * @param local_user
     * @return
     */
    public boolean delTddeviceDevice(String ip, String local_user) {
        boolean flag = false;
            /* TODO output your page here. You may use following sample code. */
        TddeviceManageService tds = new TddeviceManageService();
        flag = tds.delete(ip, local_user);
        return flag;
    }


    public String queryTddeviceDevice() {
        TddeviceManageService tds = new TddeviceManageService();
        JSONArray srr = tds.findAll();
        return srr.toString();
    }

    public boolean updateTddeviceDevice(String old_ip, String old_user, String ip, String port, String local_user, String pswd, String freq, String local_path, String desc, String up2ip, String up2port, String up2user, String up2pswd) {
        TdDevice bean = new TdDevice();
        bean.setLocal_ip(ip);
        bean.setLocal_port(port);
        bean.setLocal_user(local_user);
        bean.setLocal_pswd(pswd);
        bean.setFreq(freq);
        bean.setLocal_path(local_path);
        bean.setIsRun("0");
        bean.setDesc(desc);
        bean.setUp2_ip(up2ip);
        bean.setUp2_port(up2port);
        bean.setUp2_user(up2user);
        bean.setUp2_pswd(up2pswd);
        boolean flag = false;

            /* TODO output your page here. You may use following sample code. */
        TddeviceManageService tdms = new TddeviceManageService();
        flag = tdms.update(bean, old_ip, old_user);
        return flag;
    }
}
